﻿using DevExpress.XtraGrid.Demos.util;
using DiaoPaiDaYin;
using DXApplicationTangche.DTO;
using DXApplicationTangche.service;
using DXApplicationTangche.UC.订单.service;
using DXApplicationTangche.UC.货号管理.service;
using DXApplicationTangche.UC.销售台账.service;
using DXApplicationTangche.UC.门店下单.DTO;
using mendian;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.门店下单.service
{
    public class 下单相关Service
    {
        #region 返单号
        
        /// <summary>
        /// 查询客户的历史订单信息
        /// </summary>
        /// <param name="customerId"></param>
        /// <returns></returns>
        public static List<orderDTO> get参考历史订单(String customerId)
        {
            try
            {
                return
                    FunctionHelper.JsonDeserialization<List<orderDTO>>(
                        RestCall.httpGetMethod(
                            URL.接口url + "/barcode/getCustomerHistoryOrder?customerId=" + customerId
                            )
                        );
            }
            catch
            {
                return new List<orderDTO>();
            }
        }

        /// <summary>
        /// 查询客户的历史订单信息
        /// </summary>
        /// <param name="customerId"></param>
        /// <returns></returns>
        public static List<orderDTO> get参考历史订单By量体id和手机(String customerCountId, String mobile)
        {
            try
            {
                return
                    FunctionHelper.JsonDeserialization<List<orderDTO>>(
                        RestCall.httpGetMethod(
                            URL.接口url + "/barcode/getHistoryOrderByCountIdAndMobile?customerCountId=" + customerCountId + "&mobile=" + mobile
                            )
                        );
            }
            catch
            {
                return new List<orderDTO>();
            }
        }
        /// <summary>
        /// 电话查询客户历史订单
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns></returns>
        public static List<OrderStatusIndexDTO> getOrderIndexByMobile(String mobile)
        {
            try
            {
                return
                    FunctionHelper.JsonDeserialization<List<OrderStatusIndexDTO>>(
                        RestCall.httpGetMethod(
                            URL.接口url + "/customer/getOrderIndexByMobile?mobile=" + mobile
                            )
                    );
            }
            catch
            {
                return new List<OrderStatusIndexDTO>();
            }
        }
        #endregion

        /// <summary>
        /// select接口查设计点
        /// </summary>
        /// <param name="styleNameCn"></param>
        /// <returns></returns>
        public static List<DTODesignPoints> select接口查设计点(String styleNameCn)
        {
            List<DTODesignPoints> Dto设计点s = FunctionHelper
                .JsonDeserialization<List<DTODesignPoints>>(
                RestCall.httpGetMethod(
                    URL.接口url +
                    "/recipe/getCraftFacadeStyleDesignDTOByStyleNameCn?styleNameCn=" + styleNameCn));
            for (int i = Dto设计点s.Count-1; i > 0; i--)
            {
                if (String.IsNullOrWhiteSpace(Dto设计点s[i].optionValue) && String.IsNullOrWhiteSpace(Dto设计点s[i].name))
                {
                    Dto设计点s.RemoveAt(i);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine(Dto设计点s[i].optionValue + "=========" + Dto设计点s[i].name + "=======================");
                }
            }
            return Dto设计点s;
        }

        /// <summary>
        /// 查询默认设计点及可选设计点
        /// </summary>
        /// <param name="styleNameCn"></param>
        /// <returns></returns>
        public static List<DesignPointsFacadeDTO> getDesignPointsFacadeByStyleName(String styleNameCn)
        {
            return
                FunctionHelper.JsonDeserialization<List<DesignPointsFacadeDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/recipe/getDesignPointsFacadeByStyleName?styleNameCn=" + styleNameCn
                        )
                    );
        }
        /// <summary>
        /// 查询默认设计点及可选设计点：坚山
        /// </summary>
        /// <param name="styleId"></param>
        /// <returns></returns>
        public static List<DesignPointsFacadeDTO> getStyleDesignById(String styleId)
        {
            return
                FunctionHelper.JsonDeserialization<List<DesignPointsFacadeDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/style/getStyleDesignById?styleId=" + styleId
                        )
                    );
        }
        /// <summary>
        /// 通过款名查询设计点导入维护记录
        /// </summary>
        /// <param name="styleNameCn"></param>
        /// <returns></returns>
        public static List<设计点Excel格式> getStyleDesignImportRecordByStyleNameCN(String styleNameCn)
        {
            List<设计点Excel格式> 设计点Excel格式s = new List<设计点Excel格式>();
            List<StyleDesignExcelDTO> styleDesignExcelDTOs =
                FunctionHelper.JsonDeserialization<List<StyleDesignExcelDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/style/getStyleDesignImportRecordByStyleNameCN?styleNameCN=" + styleNameCn
                        )
                    );
            if (styleDesignExcelDTOs.Count > 0)
            {
                foreach (StyleDesignExcelDTO item in styleDesignExcelDTOs)
                {
                    设计点Excel格式s.Add(new 设计点Excel格式(item));
                }
            }
            return 设计点Excel格式s;
        }
        /// <summary>
        /// 上传文件并返回OrderCommits
        /// </summary>
        /// <param name="ofd"></param>
        /// <returns></returns>
        public static String saveKashiyamaOrderByFile(OpenFileDialog ofd)
        {
            String xx = ofd.FileName;
            return
                FileService.UploadRequest(
                    URL.接口url + "/kashiyamaUS/saveKashiyamaOrderByFile",
                    ofd.FileName,
                    Path.GetFileName(ofd.FileName),
                    "multipartFile"
                    );
        }

        public static List<OrderStatusSaleIndexDTO> updateAddressInfoByCSV(List<KashiyamaCSV> kashiyamaCSVDTOS)
        {
           return
                FunctionHelper.JsonDeserialization<List<OrderStatusSaleIndexDTO>>(
                    RestCall.PostHttp(
                        URL.接口url + "/kashiyamaUS/updateAddressInfoByCSV",
                        FunctionHelper.JsonSerialization(kashiyamaCSVDTOS)
                        )
                    );
        }

        /// <summary>
        /// 取可选设计点
        /// </summary>
        /// <param name="itemCd"></param>
        /// <returns></returns>
        public static List<DesignOptionDTO> getDesignOption(String itemCd)
        {
            return
                 FunctionHelper.JsonDeserialization<List<DesignOptionDTO>>(
                     RestCall.httpGetMethod(
                         URL.接口url + "/barcode/getDesignOption?itemCd=" + itemCd
                         )
                     );
        }
    }

    public class KashiyamaCSV
    {
        public String productNo { get; set; }
        public String mobile { get; set; }
        public String consignee { get; set; }
        public String addressProvince { get; set; }//省
        public String addressCity { get; set; }//市
        public String addressDistrict { get; set; }//区
        public String addressDetail { get; set; }//详细地址
        
        public KashiyamaCSV(DataRow dr)
        {
            this.productNo = dr["RefNumber"].ToString();
            this.mobile = dr["RecipientPhone"].ToString();
            this.consignee = dr["RecipientFullName"].ToString();
            this.addressProvince = dr["RecipientProvince"].ToString();
            this.addressCity = dr["RecipientCity"].ToString();
            this.addressDistrict = dr["RecipientAddress1"].ToString();
            this.addressDetail = dr["RecipientAddress2"].ToString() + " " + dr["RecipientAddress3"].ToString();
        }
    }

    /// <summary>
    /// 默认设计点及可选设计点
    /// </summary>
    public class DesignPointsFacadeDTO
    {
        public DTODesignPoints defaultDtoDesignPoints;    //  默认设计点
        public List<DTODesignPoints> optionDtoDesignPoints;    //  可选设计点
        public DesignPointsFacadeDTO()
        {

        }

    }

    public class DTO选择用户
    {
        public  String customerId { get; set; }
        public  String addressId { get; set; }
        public  String customerName { get; set; }
        public  String customerCountId { get; set; }
        public String shopId { get; set; }
        public DTO选择用户()
        {

        }
        public void build选择客户(CustomerChooseInfoDTO customerChooseInfoDTO)
        {
            this.addressId = customerChooseInfoDTO.addressId;
            this.customerCountId = customerChooseInfoDTO.countId;
            this.customerId = customerChooseInfoDTO.customerId;
            this.customerName = customerChooseInfoDTO.customerCountName;
            this.shopId = "18";
        }
    }
}
